source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-011.rds.xz")
summary(model)
SOM of size 10x10 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 1065343 objects.
Mean distance to the closest unit in the map: 0.603.
plot(model, type="changes")
df <- mpr.load_data("datos_dia_2k.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:1065343 Length:1065343 Min. : 1.0 Min. :-196.0
Class :character Class :character 1st Qu.: 91.0 1st Qu.: 144.0
Mode :character Mode :character Median :183.0 Median : 201.0
Mean :182.8 Mean : 201.5
3rd Qu.:274.0 3rd Qu.: 263.0
Max. :366.0 Max. : 469.0
tmin precip nevada prof_nieve
Min. :-252.00 Min. : 0.00 Min. :0 Min. : 0.0000
1st Qu.: 47.00 1st Qu.: 0.00 1st Qu.:0 1st Qu.: 0.0000
Median : 100.00 Median : 0.00 Median :0 Median : 0.0000
Mean : 97.54 Mean : 17.05 Mean :0 Mean : 0.6185
3rd Qu.: 153.00 3rd Qu.: 2.00 3rd Qu.:0 3rd Qu.: 0.0000
Max. : 332.00 Max. :3361.00 Max. :0 Max. :1240.0000
longitud latitud altitud
Min. :27.82 Min. :-17.889 Min. : 1
1st Qu.:39.47 1st Qu.: -4.850 1st Qu.: 47
Median :41.29 Median : -1.411 Median : 287
Mean :40.10 Mean : -2.391 Mean : 486
3rd Qu.:42.22 3rd Qu.: 1.296 3rd Qu.: 691
Max. :43.57 Max. : 4.216 Max. :2535
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13
13261 11494 18100 18351 18232 13049 8859 1649 672 133 11960 13624 11825
14 15 16 17 18 19 20 21 22 23 24 25 26
11043 11893 17538 14312 5378 2199 1490 16415 7627 10189 6979 9174 11567
27 28 29 30 31 32 33 34 35 36 37 38 39
12881 7659 4243 8730 7714 9946 6079 13700 9665 11359 9791 8748 2413
40 41 42 43 44 45 46 47 48 49 50 51 52
10397 11331 6538 11510 11543 10201 10522 10850 14795 3186 12750 15990 15920
53 54 55 56 57 58 59 60 61 62 63 64 65
9085 13117 9269 7082 4695 12700 10074 6219 13647 14930 11258 10348 9904
66 67 68 69 70 71 72 73 74 75 76 77 78
5334 10274 10821 2924 9788 11300 13907 11738 20108 13165 10387 7309 9681
79 80 81 82 83 84 85 86 87 88 89 90 91
8863 9382 13283 6493 15768 13115 11962 15932 18982 7470 6912 6677 9351
92 93 94 95 96 97 98 99 100
15568 23893 17335 19078 7695 9256 8050 15497 10243
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 10*10;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("fecha_cnt", "tmax", "tmin", "precip", "longitud", "latitud", "altitud")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
fecha_cnt tmax tmin precip longitud latitud
[1,] 0.1283135 -0.6991573 -0.7457657 0.1941083 0.54821738 0.4429048
[2,] 0.6350321 0.3295530 0.3036102 -0.1590133 -0.01254259 0.1250637
altitud
[1,] 0.50755497
[2,] -0.02289429
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
longitud altitud latitud fecha_cnt precip tmax tmin
0.9742736 0.9609069 0.9584478 0.9560576 0.9547634 0.9440945 0.9404333
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-196 Min. :-252.00 Min. : 0.00 Min. :0
1st Qu.: 91.0 1st Qu.: 145 1st Qu.: 47.00 1st Qu.: 0.00 1st Qu.:0
Median :183.0 Median : 202 Median : 100.00 Median : 0.00 Median :0
Mean :182.7 Mean : 202 Mean : 97.68 Mean : 13.04 Mean :0
3rd Qu.:274.0 3rd Qu.: 263 3rd Qu.: 153.00 3rd Qu.: 1.00 3rd Qu.:0
Max. :366.0 Max. : 469 Max. : 332.00 Max. :357.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.47 1st Qu.: -4.850 1st Qu.: 47.0
Median : 0.0000 Median :41.29 Median : -1.411 Median : 287.0
Mean : 0.5938 Mean :40.10 Mean : -2.401 Mean : 484.5
3rd Qu.: 0.0000 3rd Qu.:42.22 3rd Qu.: 1.296 3rd Qu.: 690.0
Max. :1240.0000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-124.0 Min. :-157.00 Min. : 267.0
1st Qu.: 90.0 1st Qu.: 98.0 1st Qu.: 45.25 1st Qu.: 353.0
Median :217.0 Median : 144.0 Median : 91.00 Median : 415.0
Mean :195.8 Mean : 141.6 Mean : 81.23 Mean : 469.2
3rd Qu.:299.0 3rd Qu.: 191.0 3rd Qu.: 128.00 3rd Qu.: 530.0
Max. :366.0 Max. : 369.0 Max. : 254.00 Max. :1206.0
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.8889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.87 1st Qu.: -3.9876
Median :0 Median : 0.000 Median :41.96 Median : 0.7789
Mean :0 Mean : 3.432 Mean :41.14 Mean : -1.1966
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.47 3rd Qu.: 1.8375
Max. :0 Max. :899.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 61.0
Median : 287.0
Mean : 659.1
3rd Qu.: 900.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 21.0 Min. : 7.0 Min. :-41.0 Min. :1208 Min. :0
1st Qu.: 80.0 1st Qu.: 80.0 1st Qu.: 47.0 1st Qu.:1300 1st Qu.:0
Median :283.0 Median :133.0 Median :102.0 Median :1393 Median :0
Mean :217.2 Mean :139.1 Mean : 92.8 Mean :1518 Mean :0
3rd Qu.:306.0 3rd Qu.:193.0 3rd Qu.:143.0 3rd Qu.:1598 3rd Qu.:0
Max. :354.0 Max. :282.0 Max. :202.0 Max. :3361 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:39.48 1st Qu.: -1.1692 1st Qu.: 43.0
Median : 0.000 Median :40.80 Median : 0.4914 Median : 261.0
Mean : 8.256 Mean :39.53 Mean : -1.3609 Mean : 622.9
3rd Qu.: 0.000 3rd Qu.:41.84 3rd Qu.: 1.7678 3rd Qu.:1055.0
Max. :559.000 Max. :43.57 Max. : 3.0967 Max. :2519.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-196.0 Min. :-252.00 Min. : 0.00
1st Qu.: 54.0 1st Qu.: 114.0 1st Qu.: 16.00 1st Qu.: 0.00
Median :111.0 Median : 152.0 Median : 54.00 Median : 0.00
Mean :159.2 Mean : 147.2 Mean : 49.49 Mean : 20.82
3rd Qu.:306.0 3rd Qu.: 186.0 3rd Qu.: 86.00 3rd Qu.: 10.00
Max. :366.0 Max. : 389.0 Max. : 264.00 Max. :357.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.41 1st Qu.: -4.010
Median :0 Median : 0.000 Median :41.59 Median : -1.229
Mean :0 Mean : 1.075 Mean :41.06 Mean : -1.562
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.38 3rd Qu.: 1.363
Max. :0 Max. :1240.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 87.0
Median : 459.0
Mean : 619.8
3rd Qu.: 873.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-32.0 Min. :-75.0 Min. : 0.000 Min. :0
1st Qu.:168.0 1st Qu.:233.0 1st Qu.:127.0 1st Qu.: 0.000 1st Qu.:0
Median :215.0 Median :268.0 Median :158.0 Median : 0.000 Median :0
Mean :211.3 Mean :269.1 Mean :156.6 Mean : 3.523 Mean :0
3rd Qu.:260.0 3rd Qu.:305.0 3rd Qu.:187.0 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :469.0 Max. :332.0 Max. :332.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1
1st Qu.: 0.0000 1st Qu.:37.79 1st Qu.: -5.879 1st Qu.: 33
Median : 0.0000 Median :40.84 Median : -1.861 Median : 123
Mean : 0.0054 Mean :38.92 Mean : -3.427 Mean : 319
3rd Qu.: 0.0000 3rd Qu.:41.81 3rd Qu.: 1.179 3rd Qu.: 554
Max. :1039.0000 Max. :43.57 Max. : 4.216 Max. :2371
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-124.0 Min. :-157.00 Min. : 267.0
1st Qu.: 90.0 1st Qu.: 98.0 1st Qu.: 45.25 1st Qu.: 353.0
Median :217.0 Median : 144.0 Median : 91.00 Median : 415.0
Mean :195.8 Mean : 141.6 Mean : 81.23 Mean : 469.2
3rd Qu.:299.0 3rd Qu.: 191.0 3rd Qu.: 128.00 3rd Qu.: 530.0
Max. :366.0 Max. : 369.0 Max. : 254.00 Max. :1206.0
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.8889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.87 1st Qu.: -3.9876
Median :0 Median : 0.000 Median :41.96 Median : 0.7789
Mean :0 Mean : 3.432 Mean :41.14 Mean : -1.1966
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.47 3rd Qu.: 1.8375
Max. :0 Max. :899.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 61.0
Median : 287.0
Mean : 659.1
3rd Qu.: 900.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 21.0 Min. : 7.0 Min. :-41.0 Min. :1208 Min. :0
1st Qu.: 80.0 1st Qu.: 80.0 1st Qu.: 47.0 1st Qu.:1300 1st Qu.:0
Median :283.0 Median :133.0 Median :102.0 Median :1393 Median :0
Mean :217.2 Mean :139.1 Mean : 92.8 Mean :1518 Mean :0
3rd Qu.:306.0 3rd Qu.:193.0 3rd Qu.:143.0 3rd Qu.:1598 3rd Qu.:0
Max. :354.0 Max. :282.0 Max. :202.0 Max. :3361 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:39.48 1st Qu.: -1.1692 1st Qu.: 43.0
Median : 0.000 Median :40.80 Median : 0.4914 Median : 261.0
Mean : 8.256 Mean :39.53 Mean : -1.3609 Mean : 622.9
3rd Qu.: 0.000 3rd Qu.:41.84 3rd Qu.: 1.7678 3rd Qu.:1055.0
Max. :559.000 Max. :43.57 Max. : 3.0967 Max. :2519.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-196.0 Min. :-252.00 Min. : 0.00
1st Qu.: 54.0 1st Qu.: 114.0 1st Qu.: 16.00 1st Qu.: 0.00
Median :111.0 Median : 152.0 Median : 54.00 Median : 0.00
Mean :159.2 Mean : 147.2 Mean : 49.49 Mean : 20.82
3rd Qu.:306.0 3rd Qu.: 186.0 3rd Qu.: 86.00 3rd Qu.: 10.00
Max. :366.0 Max. : 389.0 Max. : 264.00 Max. :357.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.41 1st Qu.: -4.010
Median :0 Median : 0.000 Median :41.59 Median : -1.229
Mean :0 Mean : 1.075 Mean :41.06 Mean : -1.562
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.38 3rd Qu.: 1.363
Max. :0 Max. :1240.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 87.0
Median : 459.0
Mean : 619.8
3rd Qu.: 873.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 3.0 Min. :128.0 Min. : -4.0 Min. : 0.000 Min. :0
1st Qu.:175.0 1st Qu.:240.0 1st Qu.:126.0 1st Qu.: 0.000 1st Qu.:0
Median :217.0 Median :275.0 Median :155.0 Median : 0.000 Median :0
Mean :216.1 Mean :275.4 Mean :155.4 Mean : 3.373 Mean :0
3rd Qu.:259.0 3rd Qu.:310.0 3rd Qu.:185.0 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :469.0 Max. :332.0 Max. :128.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.47 1st Qu.:-4.049 1st Qu.: 42.0
Median : 0.0000 Median :41.17 Median :-0.482 Median : 158.0
Mean : 0.0062 Mean :40.57 Mean :-1.439 Mean : 308.7
3rd Qu.: 0.0000 3rd Qu.:41.98 3rd Qu.: 1.384 3rd Qu.: 554.0
Max. :1039.0000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-124.0 Min. :-157.00 Min. : 267.0
1st Qu.: 90.0 1st Qu.: 98.0 1st Qu.: 45.25 1st Qu.: 353.0
Median :217.0 Median : 144.0 Median : 91.00 Median : 415.0
Mean :195.8 Mean : 141.6 Mean : 81.23 Mean : 469.2
3rd Qu.:299.0 3rd Qu.: 191.0 3rd Qu.: 128.00 3rd Qu.: 530.0
Max. :366.0 Max. : 369.0 Max. : 254.00 Max. :1206.0
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.8889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.87 1st Qu.: -3.9876
Median :0 Median : 0.000 Median :41.96 Median : 0.7789
Mean :0 Mean : 3.432 Mean :41.14 Mean : -1.1966
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.47 3rd Qu.: 1.8375
Max. :0 Max. :899.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 61.0
Median : 287.0
Mean : 659.1
3rd Qu.: 900.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 21.0 Min. : 7.0 Min. :-41.0 Min. :1208 Min. :0
1st Qu.: 80.0 1st Qu.: 80.0 1st Qu.: 47.0 1st Qu.:1300 1st Qu.:0
Median :283.0 Median :133.0 Median :102.0 Median :1393 Median :0
Mean :217.2 Mean :139.1 Mean : 92.8 Mean :1518 Mean :0
3rd Qu.:306.0 3rd Qu.:193.0 3rd Qu.:143.0 3rd Qu.:1598 3rd Qu.:0
Max. :354.0 Max. :282.0 Max. :202.0 Max. :3361 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:39.48 1st Qu.: -1.1692 1st Qu.: 43.0
Median : 0.000 Median :40.80 Median : 0.4914 Median : 261.0
Mean : 8.256 Mean :39.53 Mean : -1.3609 Mean : 622.9
3rd Qu.: 0.000 3rd Qu.:41.84 3rd Qu.: 1.7678 3rd Qu.:1055.0
Max. :559.000 Max. :43.57 Max. : 3.0967 Max. :2519.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-32.0 Min. :-75.0 Min. : 0.000 Min. :0
1st Qu.: 90.0 1st Qu.:208.0 1st Qu.:145.0 1st Qu.: 0.000 1st Qu.:0
Median :179.0 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :180.8 Mean :229.1 Mean :164.5 Mean : 4.478 Mean :0
3rd Qu.:272.0 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :429.0 Max. :322.0 Max. :332.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.38 Mean :-16.06 Mean : 384.3
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-65.0 Min. :-240.00 Min. : 0.00 Min. :0
1st Qu.: 51.0 1st Qu.:122.0 1st Qu.: 22.00 1st Qu.: 0.00 1st Qu.:0
Median :104.0 Median :157.0 Median : 57.00 Median : 0.00 Median :0
Mean :156.2 Mean :155.1 Mean : 53.92 Mean : 20.59 Mean :0
3rd Qu.:310.0 3rd Qu.:189.0 3rd Qu.: 87.00 3rd Qu.: 9.00 3rd Qu.:0
Max. :366.0 Max. :389.0 Max. : 264.00 Max. :357.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1
1st Qu.: 0.0000 1st Qu.:40.30 1st Qu.: -4.680 1st Qu.: 71
Median : 0.0000 Median :41.39 Median : -1.861 Median : 370
Mean : 0.1084 Mean :40.90 Mean : -1.872 Mean : 420
3rd Qu.: 0.0000 3rd Qu.:42.24 3rd Qu.: 1.168 3rd Qu.: 691
Max. :1240.0000 Max. :43.57 Max. : 4.216 Max. :1894
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 3.0 Min. :128.0 Min. : -4.0 Min. : 0.000 Min. :0
1st Qu.:175.0 1st Qu.:240.0 1st Qu.:126.0 1st Qu.: 0.000 1st Qu.:0
Median :217.0 Median :275.0 Median :155.0 Median : 0.000 Median :0
Mean :216.1 Mean :275.4 Mean :155.4 Mean : 3.373 Mean :0
3rd Qu.:259.0 3rd Qu.:310.0 3rd Qu.:185.0 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :469.0 Max. :332.0 Max. :128.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.47 1st Qu.:-4.049 1st Qu.: 42.0
Median : 0.0000 Median :41.17 Median :-0.482 Median : 158.0
Mean : 0.0062 Mean :40.57 Mean :-1.439 Mean : 308.7
3rd Qu.: 0.0000 3rd Qu.:41.98 3rd Qu.: 1.384 3rd Qu.: 554.0
Max. :1039.0000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-124.0 Min. :-157.00 Min. : 267.0
1st Qu.: 90.0 1st Qu.: 98.0 1st Qu.: 45.25 1st Qu.: 353.0
Median :217.0 Median : 144.0 Median : 91.00 Median : 415.0
Mean :195.8 Mean : 141.6 Mean : 81.23 Mean : 469.2
3rd Qu.:299.0 3rd Qu.: 191.0 3rd Qu.: 128.00 3rd Qu.: 530.0
Max. :366.0 Max. : 369.0 Max. : 254.00 Max. :1206.0
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.8889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.87 1st Qu.: -3.9876
Median :0 Median : 0.000 Median :41.96 Median : 0.7789
Mean :0 Mean : 3.432 Mean :41.14 Mean : -1.1966
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.47 3rd Qu.: 1.8375
Max. :0 Max. :899.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 61.0
Median : 287.0
Mean : 659.1
3rd Qu.: 900.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 21.0 Min. : 7.0 Min. :-41.0 Min. :1208 Min. :0
1st Qu.: 80.0 1st Qu.: 80.0 1st Qu.: 47.0 1st Qu.:1300 1st Qu.:0
Median :283.0 Median :133.0 Median :102.0 Median :1393 Median :0
Mean :217.2 Mean :139.1 Mean : 92.8 Mean :1518 Mean :0
3rd Qu.:306.0 3rd Qu.:193.0 3rd Qu.:143.0 3rd Qu.:1598 3rd Qu.:0
Max. :354.0 Max. :282.0 Max. :202.0 Max. :3361 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:39.48 1st Qu.: -1.1692 1st Qu.: 43.0
Median : 0.000 Median :40.80 Median : 0.4914 Median : 261.0
Mean : 8.256 Mean :39.53 Mean : -1.3609 Mean : 622.9
3rd Qu.: 0.000 3rd Qu.:41.84 3rd Qu.: 1.7678 3rd Qu.:1055.0
Max. :559.000 Max. :43.57 Max. : 3.0967 Max. :2519.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-196.00 Min. :-252.00 Min. : 0.00
1st Qu.: 91.0 1st Qu.: 30.00 1st Qu.: -31.00 1st Qu.: 0.00
Median :184.0 Median : 86.00 Median : 17.00 Median : 0.00
Mean :182.3 Mean : 87.35 Mean : 16.08 Mean : 22.57
3rd Qu.:272.0 3rd Qu.: 145.00 3rd Qu.: 68.00 3rd Qu.: 17.00
Max. :366.0 Max. : 313.00 Max. : 202.00 Max. :297.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :40.78 Min. :-5.6492
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.363 Mean :42.24 Mean : 0.7762
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1199.000 Max. :42.77 Max. : 2.4378
altitud
Min. : 823
1st Qu.:1894
Median :2230
Mean :2127
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-32.0 Min. :-75.0 Min. : 0.000 Min. :0
1st Qu.: 90.0 1st Qu.:208.0 1st Qu.:145.0 1st Qu.: 0.000 1st Qu.:0
Median :179.0 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :180.8 Mean :229.1 Mean :164.5 Mean : 4.478 Mean :0
3rd Qu.:272.0 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :429.0 Max. :322.0 Max. :332.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.38 Mean :-16.06 Mean : 384.3
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-61 Min. :-228.00 Min. : 0.00 Min. :0
1st Qu.: 36.00 1st Qu.:126 1st Qu.: 25.00 1st Qu.: 0.00 1st Qu.:0
Median : 73.00 Median :162 Median : 61.00 Median : 0.00 Median :0
Mean : 84.88 Mean :160 Mean : 57.77 Mean : 26.47 Mean :0
3rd Qu.:112.00 3rd Qu.:194 3rd Qu.: 92.00 3rd Qu.: 17.00 3rd Qu.:0
Max. :366.00 Max. :389 Max. : 264.00 Max. :357.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.30 1st Qu.: -4.767 1st Qu.: 61.0
Median : 0.0000 Median :41.43 Median : -1.863 Median : 349.0
Mean : 0.1225 Mean :40.96 Mean : -1.968 Mean : 407.2
3rd Qu.: 0.0000 3rd Qu.:42.27 3rd Qu.: 1.165 3rd Qu.: 687.0
Max. :1209.0000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 3.0 Min. :128.0 Min. : -4.0 Min. : 0.000 Min. :0
1st Qu.:175.0 1st Qu.:240.0 1st Qu.:126.0 1st Qu.: 0.000 1st Qu.:0
Median :217.0 Median :275.0 Median :155.0 Median : 0.000 Median :0
Mean :216.1 Mean :275.4 Mean :155.4 Mean : 3.373 Mean :0
3rd Qu.:259.0 3rd Qu.:310.0 3rd Qu.:185.0 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :469.0 Max. :332.0 Max. :128.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.47 1st Qu.:-4.049 1st Qu.: 42.0
Median : 0.0000 Median :41.17 Median :-0.482 Median : 158.0
Mean : 0.0062 Mean :40.57 Mean :-1.439 Mean : 308.7
3rd Qu.: 0.0000 3rd Qu.:41.98 3rd Qu.: 1.384 3rd Qu.: 554.0
Max. :1039.0000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1 Min. :-124.0 Min. :-157.00 Min. :267.0 Min. :0
1st Qu.: 89 1st Qu.: 98.0 1st Qu.: 45.00 1st Qu.:350.0 1st Qu.:0
Median :208 Median : 144.0 Median : 90.00 Median :402.0 Median :0
Mean :194 Mean : 141.7 Mean : 80.64 Mean :433.9 Mean :0
3rd Qu.:299 3rd Qu.: 192.0 3rd Qu.: 128.00 3rd Qu.:494.0 3rd Qu.:0
Max. :366 Max. : 369.0 Max. : 254.00 Max. :763.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.87 1st Qu.: -4.0103 1st Qu.: 64.0
Median : 0.000 Median :41.98 Median : 0.7433 Median : 316.0
Mean : 3.685 Mean :41.16 Mean : -1.2645 Mean : 659.8
3rd Qu.: 0.000 3rd Qu.:42.47 3rd Qu.: 1.8267 3rd Qu.: 897.5
Max. :899.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 3.0 Min. :-55.0 Min. :-92.00 Min. : 730.0 Min. :0
1st Qu.:110.8 1st Qu.: 98.5 1st Qu.: 50.00 1st Qu.: 803.0 1st Qu.:0
Median :271.0 Median :143.0 Median : 97.50 Median : 871.5 Median :0
Mean :218.4 Mean :140.5 Mean : 88.44 Mean : 902.7 Mean :0
3rd Qu.:307.0 3rd Qu.:189.0 3rd Qu.:133.00 3rd Qu.: 984.0 3rd Qu.:0
Max. :362.0 Max. :321.0 Max. :240.00 Max. :1206.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.8889 Min. : 1.00
1st Qu.: 0.0000 1st Qu.:40.80 1st Qu.: 0.0714 1st Qu.: 56.75
Median : 0.0000 Median :41.60 Median : 1.0544 Median : 252.00
Mean : 0.3125 Mean :40.84 Mean : -0.3623 Mean : 649.78
3rd Qu.: 0.0000 3rd Qu.:42.29 3rd Qu.: 2.1553 3rd Qu.: 953.00
Max. :150.0000 Max. :43.57 Max. : 4.2156 Max. :2535.00
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 21.0 Min. : 7.0 Min. :-41.0 Min. :1208 Min. :0
1st Qu.: 80.0 1st Qu.: 80.0 1st Qu.: 47.0 1st Qu.:1300 1st Qu.:0
Median :283.0 Median :133.0 Median :102.0 Median :1393 Median :0
Mean :217.2 Mean :139.1 Mean : 92.8 Mean :1518 Mean :0
3rd Qu.:306.0 3rd Qu.:193.0 3rd Qu.:143.0 3rd Qu.:1598 3rd Qu.:0
Max. :354.0 Max. :282.0 Max. :202.0 Max. :3361 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:39.48 1st Qu.: -1.1692 1st Qu.: 43.0
Median : 0.000 Median :40.80 Median : 0.4914 Median : 261.0
Mean : 8.256 Mean :39.53 Mean : -1.3609 Mean : 622.9
3rd Qu.: 0.000 3rd Qu.:41.84 3rd Qu.: 1.7678 3rd Qu.:1055.0
Max. :559.000 Max. :43.57 Max. : 3.0967 Max. :2519.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-196.00 Min. :-252.00 Min. : 0.00
1st Qu.: 91.0 1st Qu.: 30.00 1st Qu.: -31.00 1st Qu.: 0.00
Median :184.0 Median : 86.00 Median : 17.00 Median : 0.00
Mean :182.3 Mean : 87.35 Mean : 16.08 Mean : 22.57
3rd Qu.:272.0 3rd Qu.: 145.00 3rd Qu.: 68.00 3rd Qu.: 17.00
Max. :366.0 Max. : 313.00 Max. : 202.00 Max. :297.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :40.78 Min. :-5.6492
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.363 Mean :42.24 Mean : 0.7762
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1199.000 Max. :42.77 Max. : 2.4378
altitud
Min. : 823
1st Qu.:1894
Median :2230
Mean :2127
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-32.0 Min. :-75.0 Min. : 0.000 Min. :0
1st Qu.: 90.0 1st Qu.:208.0 1st Qu.:145.0 1st Qu.: 0.000 1st Qu.:0
Median :179.0 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :180.8 Mean :229.1 Mean :164.5 Mean : 4.478 Mean :0
3rd Qu.:272.0 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :429.0 Max. :322.0 Max. :332.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.38 Mean :-16.06 Mean : 384.3
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip
Min. :190.0 Min. :-65.0 Min. :-240.00 Min. : 0.000
1st Qu.:315.0 1st Qu.:114.0 1st Qu.: 14.00 1st Qu.: 0.000
Median :334.0 Median :146.0 Median : 47.00 Median : 0.000
Mean :330.5 Mean :143.3 Mean : 44.49 Mean : 6.211
3rd Qu.:350.0 3rd Qu.:175.0 3rd Qu.: 76.00 3rd Qu.: 1.000
Max. :366.0 Max. :306.0 Max. : 181.00 Max. :153.000
nevada prof_nieve longitud latitud
Min. :0 Min. :0.00e+00 Min. :35.28 Min. :-8.624
1st Qu.:0 1st Qu.:0.00e+00 1st Qu.:40.30 1st Qu.:-4.127
Median :0 Median :0.00e+00 Median :41.29 Median :-1.636
Mean :0 Mean :7.39e-02 Mean :40.78 Mean :-1.637
3rd Qu.:0 3rd Qu.:0.00e+00 3rd Qu.:42.07 3rd Qu.: 1.331
Max. :0 Max. :1.24e+03 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 85.0
Median : 427.0
Mean : 451.1
3rd Qu.: 775.0
Max. :1668.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-61.0 Min. :-228.00 Min. : 0.000
1st Qu.: 33.00 1st Qu.:128.0 1st Qu.: 21.00 1st Qu.: 0.000
Median : 67.00 Median :162.0 Median : 56.00 Median : 0.000
Mean : 70.34 Mean :159.7 Mean : 52.49 Mean : 6.114
3rd Qu.:102.00 3rd Qu.:194.0 3rd Qu.: 86.00 3rd Qu.: 2.000
Max. :225.00 Max. :336.0 Max. : 190.00 Max. :136.000
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :35.28 Min. :-8.624
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:40.07 1st Qu.:-4.680
Median :0 Median : 0.0000 Median :41.38 Median :-1.863
Mean :0 Mean : 0.1101 Mean :40.88 Mean :-1.942
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:42.24 3rd Qu.: 1.099
Max. :0 Max. :1209.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 61.0
Median : 353.0
Mean : 412.4
3rd Qu.: 690.0
Max. :1668.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 3.0 Min. :128.0 Min. : -4.0 Min. : 0.000 Min. :0
1st Qu.:175.0 1st Qu.:240.0 1st Qu.:126.0 1st Qu.: 0.000 1st Qu.:0
Median :217.0 Median :275.0 Median :155.0 Median : 0.000 Median :0
Mean :216.1 Mean :275.4 Mean :155.4 Mean : 3.373 Mean :0
3rd Qu.:259.0 3rd Qu.:310.0 3rd Qu.:185.0 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :469.0 Max. :332.0 Max. :128.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.47 1st Qu.:-4.049 1st Qu.: 42.0
Median : 0.0000 Median :41.17 Median :-0.482 Median : 158.0
Mean : 0.0062 Mean :40.57 Mean :-1.439 Mean : 308.7
3rd Qu.: 0.0000 3rd Qu.:41.98 3rd Qu.: 1.384 3rd Qu.: 554.0
Max. :1039.0000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-31.0 Min. :-127.00 Min. : 42.0 Min. :0
1st Qu.: 81.0 1st Qu.:120.0 1st Qu.: 57.00 1st Qu.:102.0 1st Qu.:0
Median :145.0 Median :155.0 Median : 90.00 Median :135.0 Median :0
Mean :173.6 Mean :161.9 Mean : 89.96 Mean :150.6 Mean :0
3rd Qu.:288.0 3rd Qu.:199.0 3rd Qu.: 123.00 3rd Qu.:189.0 3rd Qu.:0
Max. :366.0 Max. :389.0 Max. : 264.00 Max. :357.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1
1st Qu.: 0.0000 1st Qu.:40.80 1st Qu.: -5.498 1st Qu.: 71
Median : 0.0000 Median :41.77 Median : -1.885 Median : 286
Mean : 0.1979 Mean :41.42 Mean : -2.127 Mean : 376
3rd Qu.: 0.0000 3rd Qu.:42.59 3rd Qu.: 1.296 3rd Qu.: 617
Max. :1001.0000 Max. :43.57 Max. : 4.216 Max. :1894
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1 Min. :-124.0 Min. :-157.00 Min. :267.0 Min. :0
1st Qu.: 89 1st Qu.: 98.0 1st Qu.: 45.00 1st Qu.:350.0 1st Qu.:0
Median :208 Median : 144.0 Median : 90.00 Median :402.0 Median :0
Mean :194 Mean : 141.7 Mean : 80.64 Mean :433.9 Mean :0
3rd Qu.:299 3rd Qu.: 192.0 3rd Qu.: 128.00 3rd Qu.:494.0 3rd Qu.:0
Max. :366 Max. : 369.0 Max. : 254.00 Max. :763.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.87 1st Qu.: -4.0103 1st Qu.: 64.0
Median : 0.000 Median :41.98 Median : 0.7433 Median : 316.0
Mean : 3.685 Mean :41.16 Mean : -1.2645 Mean : 659.8
3rd Qu.: 0.000 3rd Qu.:42.47 3rd Qu.: 1.8267 3rd Qu.: 897.5
Max. :899.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 3.0 Min. :-55.0 Min. :-92.00 Min. : 730.0 Min. :0
1st Qu.:110.8 1st Qu.: 98.5 1st Qu.: 50.00 1st Qu.: 803.0 1st Qu.:0
Median :271.0 Median :143.0 Median : 97.50 Median : 871.5 Median :0
Mean :218.4 Mean :140.5 Mean : 88.44 Mean : 902.7 Mean :0
3rd Qu.:307.0 3rd Qu.:189.0 3rd Qu.:133.00 3rd Qu.: 984.0 3rd Qu.:0
Max. :362.0 Max. :321.0 Max. :240.00 Max. :1206.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.8889 Min. : 1.00
1st Qu.: 0.0000 1st Qu.:40.80 1st Qu.: 0.0714 1st Qu.: 56.75
Median : 0.0000 Median :41.60 Median : 1.0544 Median : 252.00
Mean : 0.3125 Mean :40.84 Mean : -0.3623 Mean : 649.78
3rd Qu.: 0.0000 3rd Qu.:42.29 3rd Qu.: 2.1553 3rd Qu.: 953.00
Max. :150.0000 Max. :43.57 Max. : 4.2156 Max. :2535.00
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 21.0 Min. : 7.0 Min. :-41.0 Min. :1208 Min. :0
1st Qu.: 80.0 1st Qu.: 80.0 1st Qu.: 47.0 1st Qu.:1300 1st Qu.:0
Median :283.0 Median :133.0 Median :102.0 Median :1393 Median :0
Mean :217.2 Mean :139.1 Mean : 92.8 Mean :1518 Mean :0
3rd Qu.:306.0 3rd Qu.:193.0 3rd Qu.:143.0 3rd Qu.:1598 3rd Qu.:0
Max. :354.0 Max. :282.0 Max. :202.0 Max. :3361 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:39.48 1st Qu.: -1.1692 1st Qu.: 43.0
Median : 0.000 Median :40.80 Median : 0.4914 Median : 261.0
Mean : 8.256 Mean :39.53 Mean : -1.3609 Mean : 622.9
3rd Qu.: 0.000 3rd Qu.:41.84 3rd Qu.: 1.7678 3rd Qu.:1055.0
Max. :559.000 Max. :43.57 Max. : 3.0967 Max. :2519.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-196.00 Min. :-252.00 Min. : 0.00
1st Qu.: 91.0 1st Qu.: 30.00 1st Qu.: -31.00 1st Qu.: 0.00
Median :184.0 Median : 86.00 Median : 17.00 Median : 0.00
Mean :182.3 Mean : 87.35 Mean : 16.08 Mean : 22.57
3rd Qu.:272.0 3rd Qu.: 145.00 3rd Qu.: 68.00 3rd Qu.: 17.00
Max. :366.0 Max. : 313.00 Max. : 202.00 Max. :297.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :40.78 Min. :-5.6492
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.363 Mean :42.24 Mean : 0.7762
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1199.000 Max. :42.77 Max. : 2.4378
altitud
Min. : 823
1st Qu.:1894
Median :2230
Mean :2127
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-32.0 Min. :-75.00 Min. : 0.000 Min. :0
1st Qu.: 91.0 1st Qu.:101.0 1st Qu.: 27.00 1st Qu.: 0.000 1st Qu.:0
Median :180.0 Median :143.0 Median : 65.00 Median : 0.000 Median :0
Mean :181.2 Mean :144.8 Mean : 68.34 Mean : 5.579 Mean :0
3rd Qu.:271.0 3rd Qu.:191.0 3rd Qu.:109.00 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :290.0 Max. :206.00 Max. :332.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.:0 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median :0 Median :28.31 Median :-16.5 Median :2371
Mean :0 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.:0 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :0 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip
Min. :190.0 Min. :-65.0 Min. :-240.00 Min. : 0.000
1st Qu.:315.0 1st Qu.:114.0 1st Qu.: 14.00 1st Qu.: 0.000
Median :334.0 Median :146.0 Median : 47.00 Median : 0.000
Mean :330.5 Mean :143.3 Mean : 44.49 Mean : 6.211
3rd Qu.:350.0 3rd Qu.:175.0 3rd Qu.: 76.00 3rd Qu.: 1.000
Max. :366.0 Max. :306.0 Max. : 181.00 Max. :153.000
nevada prof_nieve longitud latitud
Min. :0 Min. :0.00e+00 Min. :35.28 Min. :-8.624
1st Qu.:0 1st Qu.:0.00e+00 1st Qu.:40.30 1st Qu.:-4.127
Median :0 Median :0.00e+00 Median :41.29 Median :-1.636
Mean :0 Mean :7.39e-02 Mean :40.78 Mean :-1.637
3rd Qu.:0 3rd Qu.:0.00e+00 3rd Qu.:42.07 3rd Qu.: 1.331
Max. :0 Max. :1.24e+03 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 85.0
Median : 427.0
Mean : 451.1
3rd Qu.: 775.0
Max. :1668.0
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :107.0 Min. : 38.0 Min. : 0.000 Min. :0
1st Qu.: 90.0 1st Qu.:216.0 1st Qu.:156.0 1st Qu.: 0.000 1st Qu.:0
Median :179.0 Median :239.0 Median :178.0 Median : 0.000 Median :0
Mean :180.7 Mean :240.5 Mean :177.5 Mean : 4.329 Mean :0
3rd Qu.:272.0 3rd Qu.:265.0 3rd Qu.:205.0 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :429.0 Max. :322.0 Max. :318.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-17.75 1st Qu.: 25.0
Median :0 Median :28.46 Median :-16.33 Median : 33.0
Mean :0 Mean :28.38 Mean :-16.00 Mean :114.9
3rd Qu.:0 3rd Qu.:28.63 3rd Qu.:-13.86 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :632.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)